Interactive map of current collection (4,147 samples 01/01/23)
library(janitor)
library(tidyverse)
library(magrittr)
library(sf)
library(tmap)
library(httr)
collections <- readxl::read_excel("/Users/rof011/symbiobase/code/AUS_collections_merged.xlsx") |>
clean_names() |>
dplyr::select(sample_id, collection_date, location, site, longitude, latitude, host_family, host_genus, host_species) |>
mutate(lat=round(latitude,3), lon=round(longitude,3)) |>
na.omit(longitude) |>
st_as_sf(coords = c("longitude", "latitude"), crs = 4326)
# link to GBR shape file:
url <- "https://data.gov.au/data/dataset/51199513-98fa-46e6-b766-8e1e1c896869/resource/01573d07-ce10-461d-9f20-86e8e6cf5893/download/data.zip"
temp_zip <- tempfile()
invisible(capture.output(GET(url, write_disk(temp_zip, overwrite = TRUE))))
temp_dir <- tempdir()
unzip(temp_zip, exdir = temp_dir)
shapefiles <- list.files(temp_dir, pattern = "\\.shp$", recursive=TRUE, full.names = TRUE)
shapefile_path <- shapefiles[1]
# extract and tidy to sf
gbr_shape <- st_read(shapefile_path, quiet=TRUE) %>%
mutate(longitude = st_drop_geometry(.)$X_COORD,
latitude = st_drop_geometry(.)$Y_COORD) |>
filter(FEAT_NAME=="Reef") |>
st_set_crs(4283) |>
st_transform(20353) |>
st_make_valid() |>
clean_names() |>
dplyr::select(loc_name_s, qld_name, gbr_name, label_id, geometry, longitude, latitude) |>
mutate(Reef.Name = as.factor(gbr_name)) |>
mutate(GBRMPA.id = as.factor(label_id)) |>
mutate(id=sub("([a-zA-Z])$", "", label_id))
tmap_mode("view") +
tm_basemap("Esri.WorldImagery",
group="Satellite Map",
alpha=0.2) +
tm_shape(gbr_shape) +
tm_polygons(fill="turquoise",
fill_alpha=0.2,
color="white",
lwd=0.2,
group="Sample Locations",
popup.vars=c("Reef.Name", "GBRMPA.id")) +
tm_shape(collections) +
tm_symbols(fill="sample_id",
popup.vars=c("location", "site", "lon", "lat", "host_family", "host_genus", "host_species"),
# fill.scale=tm_scale_continuous(values="rd_bu"),
fill.legend=tm_legend_hide(),
color="black",
size=0.5,
shape=21)